#! /bin/bash

# unpacks and runs tlm extension and its tests to '$SYSCPAR_ROOT/tests/TLM-2009-07-15'
#
#
# requires:
#	$SYSCPAR_ROOT/downloads/TLM-2.0.1.tgz
#
# type --help for usage
# most of the command-line arguments are redirected to the testing script; run with no args to see usage

bname=`basename $0`
usage="$bname --help \t\t - shows this\n$bname {path|ver}\t - runs tlm examples & unit tests with SYSTEMC_HOME=<path> or SYSTEMC_HOME=\$SYSCPAR_ROOT/code/<ver>/systemc-2.2.0\n$bname --clean\t\t - removes tlm installed by this script"




name='TLM-2.0.1.tgz'
unpacked_name='TLM-2009-07-15'
case $1 in '-h'|'-help'|'--help')
	echo  -e $usage
	exit;;
esac
[[ $1 == "--clean" ]] && { rm -rf $SYSCPAR_ROOT/tests/$unpacked_name; echo 'cleaned'; exit 0; }


if [[ -d $SYSCPAR_ROOT/code/$1/systemc-2.2.0 ]]
then
	systemc_home=$SYSCPAR_ROOT/code/$1/systemc-2.2.0
else
	systemc_home=$1
fi
shift


cp $SYSCPAR_ROOT/downloads/$name $SYSCPAR_ROOT/tests/tlm.tar
cd $SYSCPAR_ROOT/tests/
tar -xf tlm.tar
rm -f tlm.tar
cd $unpacked_name
grep -Rl '\-Werror' . | xargs sed  -si 's|-Werror|-Wno-deprecated -Wno-unused -Wno-parentheses|'
env TLM_HOME=$SYSCPAR_ROOT/tests/$unpacked_name SYSTEMC_HOME=$systemc_home TARGET_ARCH=linux make -C ./examples/tlm/build-unix clean run check
env TLM_HOME=$SYSCPAR_ROOT/tests/$unpacked_name SYSTEMC_HOME=$systemc_home TARGET_ARCH=linux make -C ./unit_test/tlm/build-unix clean run check

